ABC172 C - Tsundoku
提出
WA
code: python
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# できない
# for i in range(200000):
# for j in range(200000):
# print(i, j)
for i in range(1, n):
a_sum.append(a_sum-1 + ai) for i in range(1, m):
b_sum.append(b_sum-1 + bi) ans = float('inf')
# a固定、b二分探索
for i in range(n):
if (rest < 0):
continue
b_index = bisect.bisect_left(b_sum, rest)
print(b_index)
res = (i+1) + b_index
if (res < ans):
ans = res
print(ans)
解答
code: python
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
a_sum.append(a_sum-1 + ai) for i in range(m):
b_sum.append(b_sum-1 + bi) ans = 0
# bを全部読む
j = m
for i in range(n + 1):
# aのみでさえ読めなかったら終わり
break
# 1冊ずつ諦めていく
while (b_sumj > k - a_sumi): j -= 1
res = i + j
if (res > ans):
ans = res
print(ans)
テーマ
提出
code: python
import itertools
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
wa = list(itertools.accumulate(a))
wb = list(itertools.accumulate(b))
# print(wa)
# print(wb)
# どちらから取るか
# print(pow(2, 200000))
# それぞれどこまで取るか
# print(pow(200000, 2))
ans = 0
for i, iv in enumerate(wa):
for j, jv in enumerate(wb):
if iv + jv <= k:
res = i+1 + j+1
if res > ans:
ans = res
else:
break
print(ans)
解答
code: python
import itertools
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_sum = list(itertools.accumulate(a, initial=0))
b_sum = list(itertools.accumulate(b, initial=0))
ans = 0
ok = m
for i in range(n + 1):
# a_sumi を読むのに b_sum をどれだけ減らす必要があるか while (0 <= ok and k < a_sumi + b_sumok): ok -= 1
if (0 <= ok):
ans = max(ans, i + ok)
print(ans)
メモ